package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.uilt.JsonResult;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;


//@RestController // --->@Controller + @ResponseBody
@RequestMapping("employees")
public class EmployeeController_back {

    /**
     * 需求: 员工列表
     * 请求路径: "/employees"
     * 请求方法: GET
     * 请求参数: 没有
     * 请求返回值: 看需求, 返回list
     *
     */
//    @RequestMapping(value = "/employees", method = RequestMethod.GET)
    @GetMapping
    public List<Employee> list(){
        return Arrays.asList(
                new Employee(1L, "大飞","1",new BigDecimal(1000),2L, 18,2)
                ,new Employee(2L,"小飞","1",new BigDecimal(1000),3L,17,1) );
    }

    // 查单条
//    @RequestMapping(value = "/employees/{id}",method = RequestMethod.GET)
    @GetMapping("/{id}")
    public Employee get(@PathVariable Long id){
        return new Employee(id, "张三","1",new BigDecimal(1000),2L,20,3);
    }

    // 员工添加
//    @RequestMapping(value = "/employees", method = RequestMethod.POST)
    @PostMapping
    public Employee add(Employee employee){
        employee.setId(3L);
        return employee;
    }

    // 修改
//    @RequestMapping(value = "/employees", method = RequestMethod.PUT)
    @PutMapping
    public Employee update(Employee employee){
        employee.setName(employee.getName()+"_abc");
        return employee;
    }

//    @RequestMapping(value = "/employees",method = RequestMethod.DELETE)
    @DeleteMapping
    public JsonResult delete(Long id){
        return JsonResult.error();
    }

}
